﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       Shpm.App.Input.Dao.RoomBookDao
 * 类型：       入住登记画面 数据库操作层
 * 功能说明：   入住信息做追加更新删除操作
 * 作者：       章 昕
 * 创建日期：   2007/08/24
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using Shpm.System.Db;
using Shpm.App.Commons.Db.Beans.Master;
using Shpm.App.Input.Bean;


/// <summary>
/// Summary description for RoomBookDao
/// </summary>
namespace Shpm.App.Input.Dao
{
    public class RoomBookDao : ShpmBaseDao
    {
        public RoomBookDao() { }

        // 从数据字典中取得画面列表项内容
        public const string FIND_BY_CATALOG = "CommonDictionary.FindByCatalog";

        // 从房间信息表中取得楼号列表项内容
        public const string GET_BUILDINGNO_LIST = "RoomBook.GetBuildingNoList";
        
        // 房间状态列表
        public const string LIST_ROOM_BOOK_STATUS = "RoomBook.ListRoomBookStatus";
        //读取会员信息
        public const string FIND_BY_APARTMENTSTATUS = "RoomBook.FindByApartmentStatus";
        //读取会员入住状态
        public const string FIND_BY_PERSONSTATUS = "RoomBook.FindByPersonStatus";
        public const string FIND_BY_PERSONSTATUS02 = "RoomBook.FindByPersonStatus02";
        public const string FIND_BY_PERSONSTATUS03 = "RoomBook.FindByPersonStatus03";
        public const string FIND_BY_PERSONSTATUS04 = "RoomBook.FindByPersonStatus04";
        public const string GET_STATUSCONUT = "RoomBook.GetStatusConut";
        public const string GET_STATUSCONUT03 = "RoomBook.GetStatusConut03";
        public const string INSERT_APARTMENTSTATUS = "RoomBook.InsertApartmentStatus";
        public const string INSERT_APARTMENTSTATUSHISTORY = "RoomBook.InsertApartmentStatusHistory";
        public const string UPDATE_APARTMENTSTATUS = "RoomBook.UpdateApartmentStatus";
        public const string UPDATE_APARTMENTSTATUS02 = "RoomBook.UpdateApartmentStatus02";
        public const string UPDATE_APARTMENTSTATUS04 = "RoomBook.UpdateApartmentStatus04";
        public const string GET_APARTMENTSTATUS = "RoomBook.GetApartmentStatus";

        public const string UPDATE_MEMBERSTATUS = "RoomBook.UpdateMemberStatus";
        public const string FIND_BY_APARTMENTSTATUSNO = "RoomBook.FindByApartmentStatusNo";
        

        /*
         *名称： FindByCatalog
         *功能： 取得数据字典列表对象。
         *参数： paramBean - 检索参数
         *返回： 数据字典列表 
         *说明： 从数据字典中取得画面列表项内容
        */
        public IList FindByCatalog(CommonDictionaryBean paramBean)
        {
            return base.QueryForList(FIND_BY_CATALOG, paramBean);
        }


        /*
        *名称： GetBuildingNoList
        *功能： 取得数据字典对象。
        *参数： 无
        *返回： 楼号列表
        *说明： 房间信息表中取得画面列表项内容
       */
        public IList GetBuildingNoList()
        {
            return base.QueryForList(GET_BUILDINGNO_LIST, null);
        }


        /*
         *名称： ListRoomStatus
         *功能： 取得房间状态列表对象。
         *参数： paramBean - 检索参数
         *返回： 房间状态列表 
         *说明： 
        */
        public IList ListRoomStatus(RoomBookApartBean paramBean)
        {
            return base.QueryForList(LIST_ROOM_BOOK_STATUS, paramBean);
        }
        //读取会员信息
        public ApartmentStatusBean ApartmentStatusLoad(ApartmentStatusBean paramBean)
        {
            return (ApartmentStatusBean)base.QueryForObject(FIND_BY_APARTMENTSTATUS, paramBean);
        }
        //读取会员入住状态
        public IList FindByPersonStatus(ApartmentStatusBean paramBean)
        {
            return base.QueryForList(FIND_BY_PERSONSTATUS, paramBean);
        }
        public IList FindByPersonStatus02(ApartmentStatusBean paramBean)
        {
            return base.QueryForList(FIND_BY_PERSONSTATUS02, paramBean);
        }
        public IList FindByPersonStatus03(ApartmentStatusBean paramBean)
        {
            return base.QueryForList(FIND_BY_PERSONSTATUS03, paramBean);
        }
        public IList FindByPersonStatus04(ApartmentStatusBean paramBean)
        {
            return base.QueryForList(FIND_BY_PERSONSTATUS04, paramBean);
        }
        //读取房间上限
        public ApartmentStatusBean CountLoad(ApartmentStatusBean paramBean)
        {
            return (ApartmentStatusBean)base.QueryForObject(GET_STATUSCONUT, paramBean);
        }
        public ApartmentStatusBean CountLoad03(ApartmentStatusBean paramBean)
        {
            return (ApartmentStatusBean)base.QueryForObject(GET_STATUSCONUT03, paramBean);
        }
        //插入数据
        public Object InsertApartmentStatus(ApartmentStatusBean paramBean)
        {
            return base.Insert(INSERT_APARTMENTSTATUS, paramBean);
        }
        //插入历史数据
        public Object InsertApartmentStatusHistory(ApartmentStatusBean paramBean)
        {
            return base.Insert(INSERT_APARTMENTSTATUSHISTORY, paramBean);
        }
        //更新数据
        public int UpdateApartmentStatus(ApartmentStatusBean paramBean)
        {
            return base.Update(UPDATE_APARTMENTSTATUS, paramBean);
        }
        public int UpdateApartmentStatus02(ApartmentStatusBean paramBean)
        {
            return base.Update(UPDATE_APARTMENTSTATUS02, paramBean);
        }
        public int UpdateApartmentStatus04(ApartmentStatusBean paramBean)
        {
            return base.Update(UPDATE_APARTMENTSTATUS04, paramBean);
        }
        //判断更新或插入
        public ApartmentStatusBean Load(ApartmentStatusBean paramBean)
        {
            return (ApartmentStatusBean)base.QueryForObject(GET_APARTMENTSTATUS, paramBean);
        }
        //更新会员表
        public int UpdateMemberStatus(ApartmentStatusBean paramBean)
        {
            return base.Update(UPDATE_MEMBERSTATUS, paramBean);
        }
        public int ListInsertApartmentStatus(ApartmentStatusBean dataBean)
        {

            try
            {
                ApartmentStatusBean dataBean1 = new ApartmentStatusBean();
                dataBean1.ApartmentNo = dataBean.ApartmentNo;
                dataBean1.MemberNo = dataBean.MemberNo;
                base.BeginTransaction();
                dataBean1 = this.Load(dataBean1);
                if (dataBean1 != null)
                {
                    this.UpdateApartmentStatus(dataBean);
                    this.InsertApartmentStatusHistory(dataBean);
                    this.UpdateMemberStatus(dataBean);
                }
                else
                {
                    this.InsertApartmentStatus(dataBean);
                    this.InsertApartmentStatusHistory(dataBean);
                    this.UpdateMemberStatus(dataBean);
                }
                base.CommitTransaction();
                return 1;
            }
            catch (DataAccessException e)
            {
                Console.WriteLine("********** Exec  sql error! **********");
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                base.RollBackTransaction();
                throw (e);

            }
        }

        public int ListUpdateApartmentStatus(ApartmentStatusBean dataBean)
        {

            try
            {
                base.BeginTransaction();
                this.UpdateApartmentStatus02(dataBean);
                this.InsertApartmentStatusHistory(dataBean);
                base.CommitTransaction();
                return 1;
            }
            catch (DataAccessException e)
            {
                Console.WriteLine("********** Exec  sql error! **********");
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                base.RollBackTransaction();
                throw (e);
                return -1;

            }
        }
        public int ListUpdateApartmentStatus04(ApartmentStatusBean dataBean)
        {

            try
            {
                base.BeginTransaction();
                this.UpdateApartmentStatus04(dataBean);
                this.InsertApartmentStatusHistory(dataBean);
                this.UpdateMemberStatus(dataBean);
                base.CommitTransaction();
                return 1;
            }
            catch (DataAccessException e)
            {
                Console.WriteLine("********** Exec  sql error! **********");
                Console.WriteLine(e.InnerException);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                base.RollBackTransaction();
                throw (e);
                return -1;

            }
        }
        //读取房间的入住信息
        public IList FindByApartmentStatusNo(ApartmentStatusBean paramBean)
        {
            return base.QueryForList(FIND_BY_APARTMENTSTATUSNO, paramBean);
        }
    }
}
